package com.moli.controller;

import com.moli.domain.ResponseResult;
import com.moli.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author： XC
 * @Date： 2023-06-09 11:15
 * @Description： 文件上传控制器
 */

@RestController
public class UploadController {

	@Autowired
	private UploadService uploadService;

	/**
	 * 文件上传功能
	 * @param multipartFile
	 * @return
	 */
	@PostMapping("/upload")
	public ResponseResult uploadImg(@RequestParam("img") MultipartFile multipartFile) {
		try {
			return uploadService.uploadImg(multipartFile);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("文件上传上传失败");
		}
	}
}

